package base.day26.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ReceptionDemo {
    public static void main(String[] args) throws IOException {
        //表示从10000端口接收数据
        DatagramSocket ds = new DatagramSocket(10000);
        //创建包来接收数据
        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length);
        //把接收到的数据放到新包中
        ds.receive(dp);
        //从包中获取数据
        byte[] data = dp.getData();
        //获取数据的长度
        int length = dp.getLength();
        System.out.println(new String(bytes,0,length));
        ds.close();

    }
}
